<template>
	<view class="layout">

		<view class="layout-head">
			<Search @onConfirm="onConfirm" placeholder="关键字/词/编号" v-model="initQueryParams.query" @onIcon="onFilter"></Search>
			<u-tabs :list="NavList" :is-scroll="false" :current="navCurrentIndex" @change="changeNav"></u-tabs>
		</view>

		<view class="layout-body">
			<mescroll-uni :fixed="false" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
				<Card v-for="(item,index) in data" :key="index" :data="item" :navUrl="`${navUrl}?id=${item.executeId}`"></Card>
			</mescroll-uni>
		</view>
	</view>

</template>


<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import Search from '@/components/input/index.vue'
	import Card from '@/components/card/inspection.vue'
	import PagesPollingRouterConfig from '@/pagesPolling/routerConfig.js'
	import { historySearch } from '@/apis/inspection.js'
	import { Storage_UserInfo } from '@/common/index.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			Search,
			Card,
		},

		data() {
			return {
				navheight: 0,
				head: this.$head,
				options: {},
				data: [],
				empty: false,
				navUrl: PagesPollingRouterConfig.SearchDetail,
				initQueryParams: {
					query: '',
				},
			}
		},

		onLoad(params) {
			console.log(params);
			if (params?.query) {

				let { user, assetType, unit, handleDept, OperationDept, result, startTime, endTime } = JSON.parse(params.query)
				this.$set(this.initQueryParams, 'result', result)
				// this.$set(this.initQueryParams, 'makeUser', user)
				this.$set(this.initQueryParams, 'useDept', handleDept)
				this.$set(this.initQueryParams, 'patrolDept', OperationDept)
				this.$set(this.initQueryParams, 'assertType', assetType)
				this.$set(this.initQueryParams, 'unitFolder', unit)
				this.$set(this.initQueryParams, 'startDate', startTime)
				this.$set(this.initQueryParams, 'endDate', endTime)

			}
		},
		methods: {
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let query = {
					pageSize: page.size,
					pageNum: page.num,
					query: '',
				}
				this.$set(this.initQueryParams, 'makeUser', Storage_UserInfo().id)
				Object.assign(query, this.initQueryParams)
				this.$nextTick(() => {
					historySearch(query).then((res) => {
						//联网成功的回调,隐藏下拉刷新和上拉加载的状态; 
						if (page.num == 1) this.data = []; //如果是第一页需手动制空列表
						if (res.code === 0) {
							let list = res.body.list || []
							this.mescroll.endByPage(list.length, res.body.total)
							if (list.length) {
								this.data = [...this.data, ...list]
							}
						}
					}).catch((err) => {
						//联网失败, 结束加载
						this.mescroll.endErr();
					})
				})

			},
			//输入框键盘确认时间
			onConfirm(val) {

				this.data = []
				this.$set(this.initQueryParams, 'query', val)
				this.mescroll.resetUpScroll() // 再刷新列表数据

			},
			// 输入框 筛选事件
			onFilter() {
				wx.navigateTo({
					url: PagesPollingRouterConfig.SearchFilter
				})
			},
		}
	}
</script>

<style lang="scss">
	/*根元素需要有固定的高度*/
	page {
		height: 100%;
		/* #ifdef MP-ALIPAY || MP-DINGTALK*/
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		/* #endif */

		/*需给父元素设置height:100%*/
		.page-warp {
			height: 100%;
			display: flex;
			flex-direction: column;

			/* 顶部区域 */
			.top-warp {
				font-size: 28rpx;
				padding: 20rpx;
				text-align: center;
				background-color: #CFE0DA;
			}

			/* 中间 */
			.center-warp {
				flex: 1;
				min-width: 0;
				min-height: 0;
				/* 需给flex:1的元素加上最小高,否则内容超过会溢出容器 (如:小程序Android真机) */
				display: flex;

			}

		}

		.layout {
			height: 100%;
			background-color: #F0F3F7;
			display: flex;
			flex-direction: column;


			&-head {
				// height: 200rpx; 	QW
			}

			&-body {
				padding: 0 30rpx;
				flex: 1;
				min-width: 0;
				min-height: 0;

			}
		}
	}
</style>
